package cn.blnp.net.flowable.task.drools;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <h3></h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/5/13 15:22
 */
@Slf4j
@Component
public class DeductionJavaDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {
        Object calculationResults = execution.getVariable("costCalculationResults");
        List<CostCalculation> list = JSONUtil.toList(JSONUtil.parseArray(calculationResults), CostCalculation.class);
        log.info("折扣前消费金额：{}，折扣率：{}，折扣后实际消费金额：{}",
                list.get(0).getOriginalTotalPrice(),
                list.get(0).getDiscountRatio(), list.get(0).getActualTotalPrice());
    }
}
